package com.lingshi.yingzaitownmap.controller;

import com.lingshi.yingzaitownmap.entity.domain.Dishes;
import com.lingshi.yingzaitownmap.entity.dto.PageDTO;
import com.lingshi.yingzaitownmap.entity.result.PageBean;
import com.lingshi.yingzaitownmap.entity.result.Result;
import com.lingshi.yingzaitownmap.service.DishesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class DishesController {

    @Autowired
    private DishesService dishesService;

    /**
     * 获取美食列表
     *
     * @param pageDTO 分页参数
     * @return 美食列表
     */
    @GetMapping("/api/v1/foods")
    public Result<PageBean<Dishes>> getDishes(PageDTO pageDTO) {
        log.info("获取美食列表参数: {}", pageDTO);
        return Result.success(dishesService.select(pageDTO));
    }


    /**
     * 根据id获取美食
     *
     * @param id 美食id
     * @return 美食
     */
    @GetMapping("/api/v1/foods/{id}")
    public Result<Dishes> getDishesById(@PathVariable String id) {
        log.info("获取美食id：{}", id);
        return Result.success(dishesService.getById(id));
    }


}
